package com.diandian.backend.douyin.life.exchange.controller;

import com.diandian.backend.douyin.life.exchange.service.DouyinLifeCertificateBusinessService;
import com.diandian.backend.douyin.life.exchange.service.DouyinLifeTokenBusinessService;
import com.diandian.base.boot.starter.response.BaseResult;
import com.diandian.base.boot.starter.util.ResultUtil;
import com.diandian.douyin.life.boot.starter.dto.request.CertificatePrepareReq;
import com.diandian.douyin.life.boot.starter.dto.request.CertificateVerifyReq;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/certificate")
public class DouyinLifeCertificateController {

    @Autowired
    private DouyinLifeCertificateBusinessService certificateBusinessService;

    @Autowired
    private DouyinLifeTokenBusinessService tokenBusinessService;

    /**
     * 验券准备
     * @param clientKey
     * @param clientSecret
     * @param account
     * @param req
     * @return
     */
    @PostMapping("/verification/prepare")
    public BaseResult prepare(@RequestHeader(value = "clientKey") String clientKey,
                              @RequestHeader(value = "clientSecret") String clientSecret,
                              @RequestHeader(value = "account") String account,
                              @RequestHeader(value = "belong") String belong,
                              @RequestBody CertificatePrepareReq req) {
        String token = tokenBusinessService.getToken(clientKey, clientSecret);
        return ResultUtil.makeResult(certificateBusinessService.prepare(belong, token, account, req));
    }

    /**
     * 验券
     * @param req
     * @return
     */
    @PostMapping("/verification/verify")
    public BaseResult verify(@RequestHeader(value = "clientKey") String clientKey,
                                                        @RequestHeader(value = "clientSecret") String clientSecret,
                                                        @RequestHeader(value = "belong") String belong,
                                                        @RequestBody CertificateVerifyReq req) {
        String token = tokenBusinessService.getToken(clientKey, clientSecret);
        return ResultUtil.makeResult(certificateBusinessService.verification(belong, token, req));
    }

}
